/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.validator;

import com.minierp.bean.CooperBillBean;
import com.minierp.bean.ValidatorStatus;
import com.minierp.dao.CooperBillDao;
import com.minierp.helper.EncValidatorHelper;
import com.minierp.model.CooperBill;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class CooperBillValidator implements Validator {
	private CooperBillDao cooperBillDao;

	public boolean supports(Class clazz) {
		return CooperBillBean.class.isAssignableFrom(clazz);
	}

	public CooperBillDao getCooperBillDao() {
		return this.cooperBillDao;
	}

	public void setCooperBillDao(CooperBillDao cooperBillDao) {
		this.cooperBillDao = cooperBillDao;
	}

	public void validate(Object obj, Errors errors) {
		CooperBillBean bean = (CooperBillBean) obj;
		CooperBill form = bean.getCooperBill();
		CooperBill existBill = null;
		if (form.getBillCode() != null && !form.getBillCode().trim().equals("")) {
			existBill = this.cooperBillDao.get(form.getBillCode());
		}

		ValidatorStatus s = EncValidatorHelper.cooperBillValidate(bean,
				existBill);
		if (s.isHasError()) {
			errors.rejectValue(s.getRejectName(), "", s.getRejectValue());
		}

	}
}